﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DotNetStar.TheKing.Web
{
    using DotNetStar.TheKing.Domain;
    using DotNetStar.TheKing.Infrastructure;
    using Services;

    public class PointMessageViewComponent : ViewComponent
    {
        private UserService _userService;
        public PointMessageViewComponent(UserService userService)
        {
            _userService = userService;
        }

        public async Task<IViewComponentResult> InvokeAsync()
        {
            if (User.Identity.IsAuthenticated)
            {
                if (_userService.TryGetLastUserPointFromCache(User.Identity.UserId(), out UserPointHistory userPointList))
                {
                    ViewData["UserPointList"] = userPointList;
                }
            }
            return View();
        }
    }
}
